
<template>
   <el-card class="profile-card">
    <el-form ref="form" :model="userInfo" label-width="120px">
      <el-form-item label="用户名">
        <el-input v-model="userInfo.username" disabled></el-input>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="userInfo.phone" disabled></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-input v-model="userInfo.sex" disabled>
          <template #default="{ value }">
            {{ value === '1' ? '男' : (value === '2' ? '女' : '未知') }}
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input v-model="userInfo.idNumber" disabled></el-input>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/store/user'
import { getEmployeeById } from '@/api/employee'
import { ElMessage } from 'element-plus'

const userStore = useUserStore()
const userInfo = ref({})

onMounted(async () => {
  // 获取当前登录用户ID（从store或JWT令牌中获取）
  const userId = userStore.userInfo.id

  if (!userId) {
    ElMessage.error('获取用户ID失败，请重新登录。')
    return
  }

  try {
    // 调用接口获取用户详情
    // 调用接口获取用户详情
    const response = await getEmployeeById(userId)
    userInfo.value = response.data
    console.log('用户信息:', userInfo.value)
    console.log('性别字段类型:', typeof userInfo.value.sex)
    console.log('性别字段值:', userInfo.value.sex)
  } catch (error) {
    ElMessage.error('获取个人信息失败，请稍后重试。')
  }
})
</script>

<style scoped>
.profile-card {
  max-width: 600px;
  margin: 20px auto;
  padding: 20px;
}
.profile-container {
  margin: 20px;
  min-height: calc(100vh - 100px);
}

.profile-content {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.profile-info {
  margin-top: 30px;
  width: 80%;
}
</style>